package logic

import (
	"context"
	"medicals/models/mysql"

	"medicals/medicalrpc/internal/svc"
	"medicals/medicalrpc/medicalrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MedicalListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMedicalListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MedicalListLogic {
	return &MedicalListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MedicalListLogic) MedicalList(in *medicalrpc.MedicalListRequest) (*medicalrpc.MedicalListResponse, error) {
	// todo: add your logic here and delete this line

	var medical []mysql.Medical

	mysql.DB.Debug().Find(&medical)
	var medicalList []*medicalrpc.MedicalList
	for _, m := range medical {
		list := medicalrpc.MedicalList{
			Id:    int64(m.ID),
			Image: m.Image,
			Name:  m.Name,
			Phone: m.Phone,
			Class: m.Class,
			Price: float32(m.Price),
		}
		medicalList = append(medicalList, &list)
	}
	return &medicalrpc.MedicalListResponse{
		List: medicalList,
	}, nil
}
